#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e5 + 10, INF = 0x3f3f3f3f;

ll n;
vector<ll> g[N];
ll dep[N], size[N], f[N][20];

void dfs(ll x, ll fa)
{
    dep[x] = dep[fa] + 1;
    f[x][0] = fa;
    for (ll i = 1; (1 << i) <= dep[x];i++)
        f[x][i] = f[f[x][i - 1]][i - 1];
    for (ll y : g[x])
        if (y != fa) dfs(y, x);
}

ll lca(ll x, ll y)
{
    if (dep[x] < dep[y]) swap(x, y);
    for (ll i = 19;i >= 0;i--)
        if (dep[x] - (1 << i) >= dep[y]) x = f[x][i];
    if (x == y) return x;
    for (ll i = 19;i >= 0;i--)
        if (f[x][i] != f[y][i])
            x = f[x][i], y = f[y][i];
    return f[x][0];
}

void solve()
{
    cin >> n;
    for (ll i = 1;i < n;i++) {
        ll x, y;cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(n, 0);

    ll ans = 0, t = 1;
    for (ll i = 1;i <= n;i++) {
        t = lca(t, i);
        ans += dep[t];
    }
    cout << ans;
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}